<template>
    <div class='home-container'>
        <SideNav :openeds="openeds" :activeTab="activeTab"></SideNav>
        <div class='right-container'>
            <Header class="header" :headerList="headerList"></Header>
            <div class="right-content white-color">
                <div class="search-contain">
                    <el-form :inline="true" :model="form" class="demo-form-inline">
                        <el-form-item label="账号">
                            <el-input v-model="form.name" placeholder="账号" class="static-input">
                            </el-input>
                        </el-form-item>
                        <el-form-item label="姓名">
                            <el-input v-model="form.realname" placeholder="姓名" class="static-input">
                            </el-input>
                        </el-form-item>
                        <el-form-item label="手机号码">
                            <el-input v-model="form.phone" placeholder="手机号码" class="static-input">
                            </el-input>
                        </el-form-item>
                        <el-form-item label="状态">
                            <el-select v-model="form.state" placeholder="请选择状态" class="el-select-common">
                                <el-option label="启用" value="1"></el-option>
                                <el-option label="关闭" value="-1"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item>
                            <el-button type="primary" @click="onSubmit">查询</el-button>
                            <el-button @click="resetForm()">重置</el-button>
                        </el-form-item>
                    </el-form>
                </div>
                <div class="content-contain">
                    <el-table
                        v-loading="loading"
                        :data="tableData"
                        style="width: 100%"
                        :header-cell-style="{background:'#EFF1F6',color:'#1C1C1C'}"
                        stripe>
                        <el-table-column label="账号" prop="account">
                        </el-table-column>
                        <el-table-column label="姓名" prop="name">
                        </el-table-column>
                        <el-table-column label="邀请码" prop="code">
                        </el-table-column>
                        <el-table-column label="手机号码" prop="phone">
                        </el-table-column>
                        <el-table-column label="身份">
                            <template slot-scope="scope">
                                <span>
                                    {{scope.row.type | typeStatus}}
                                </span>
                            </template>
                        </el-table-column>
                        <el-table-column label="查看课程" prop="">
                        </el-table-column>
                        <el-table-column label="状态">
                            <template slot-scope="scope">
                                <span>
                                    {{scope.row.state | status}}
                                </span>
                            </template>
                        </el-table-column>
                        <el-table-column label="操作">
                            <template slot-scope="scope">
                                <span class="operate" title="编辑" @click="editTeacher(scope.row.id)">
                                    <img src="../../src/assets/img/welcome/edit.png" alt="">
                                </span>
                            </template>
                        </el-table-column>
                    </el-table>
                </div>
                <div class="footer-contain">
                    <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
                        :page-sizes="[20, 50, 100, 200]" :page-size="pagesize"
                        layout="total, sizes, prev, pager, next, jumper" :total="total">
                    </el-pagination>
                    <div class='go-page'>确定</div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import Header from '../../src/components/Header'
import SideNav from '../../src/components/SideNav'
import {
    getTeacherPage
} from '@/api/teachList'
export default {
    name: 'home',
    data() {
        return {
            headerList: ['会员', '讲师', '讲师列表'],
            openeds: ['3', '3-2'],
            activeTab: 'Member',
            form: {
                name: '',
                realname: '',
                phone: '',
                state: ''
            },
            loading: false,
            page: 1,
            pagesize: 10,
            total: 0,
            tableData: []
        }
    },
    filters: {
        typeStatus(val) {
            let type = {
                '1': '管理员',
                '2': '讲师',
                '3': '助教'
            }
            return type[val]
        },
        status(val) {
            let type = {
                '1': '启用',
                '-1': '关闭'
            }
            return type[val]
        }
    },
    mounted() {
        this.getTeacherPage()
    },
    methods: {
        getTeacherPage() {
            this.loading = true
            getTeacherPage({
                page: this.page,
                pagesize: this.pagesize,
                name: this.form.name,
                realname: this.form.realname,
                phone: this.form.phone,
                state: this.form.state
            }).then(res => {
                this.loading = false
                if (res.code == 1) {
                    this.tableData = res.data.list
                    this.total = res.data.recordcount
                }
            }).catch(e => {
                this.loading = false
            })
        },
        handleSizeChange(val) {
            console.log(`每页 ${val} 条`)
            this.pagesize = val
            this.getTeacherPage()
        },
        handleCurrentChange(val) {
            console.log(`当前页: ${val}`)
            this.page = val
            this.getTeacherPage()
        },
        handleEdit(index, row) {
            console.log(index, row)
        },
        handleDelete(index, row) {
            console.log(index, row)
        },
        onSubmit() {
            this.getTeacherPage()
        },
        resetForm() {
            this.form.name = ''
            this.form.realname = ''
            this.form.phone = ''
            this.form.state = ''
            this.page = 1
            this.pagesize = 10
            this.getTeacherPage()
        },
        enterCell(row, column, cell, event) {
            row.showIcon = true
        },
        leaveCell(row, column, cell, event) {
            row.showIcon = false
        },
        editTeacher(id, name, desc) {
            this.$router.push({
                path: '/addTeacher',
                query: {
                    id: id,
                    action: 'edit'
                }
            })
        }
    },
    components: {
        Header,
        SideNav
    }
}

</script>
<style lang="less" scoped>
    @import url('../../src/assets/less/Mixins.less');
    @import url('../../src/assets/less/common.less');

    html,
    body {
        height: 100%
    }

    .search-contain {
        // margin-top: 20px;
        padding-left: 20px;
        padding-top: 24px;
    }

    .content-contain {
        // padding-left: 16px;
    }

    .right-container {
        background: #ffffff;
        height: 100%;
    }

    .operate {
        cursor: pointer;
        margin-right: 20px;

        img {
            width: 16px;
            height: 16px;
        }
    }

    .grid-content {
        span {
            position: relative;
            margin-right: 5px;
            top: 3px;
        }
    }

</style>
<style lang="less">
    .el-table {
        border: 1px solid rgba(223, 230, 236, 1) !important;
        border-bottom: none !important;
    }

    .el-table__header-wrapper {
        height: 40px !important;
        background: rgba(239, 241, 246, 1) !important;
    }

    .el-table__header tr,
    .el-table__header th {
        padding: 0 !important;
        height: 40px !important;
    }

    .el-table__body-wrapper {
        .el-row {
            margin-bottom: 16px !important;

            &:first-child {
                margin-top: 10px !important;
            }
        }

        tbody {

            .table__row,
            td {
                padding: 8px 0px !important;

            }

        }
    }

    .static-input {
        width: 150px !important;
        height: 40px !important;
    }

    // 分页样式
    .el-pagination {
        .el-pager {
            .number {
                margin: 0px !important;
                background: #ffffff !important;
                border: 1px solid rgba(209, 219, 229, 1);
                color: #546374 !important;
                font-weight: 400;
                border-left: none
            }

            li.active {
                background-color: #409EFF !important;
                color: #fff !important;
                border-radius: 0px !important;
                width: 29px !important;
                height: 28px !important;
                border: solid 1px #409EFF !important;
            }

            li {
                border-radius: 0px !important;
            }
        }

        .btn-prev,
        .btn-next {
            margin: 0px !important;
            background: #ffffff !important;
            border: 1px solid rgba(209, 219, 229, 1);

        }

        .btn-prev {
            border-top-right-radius: 0px !important;
            border-bottom-right-radius: 0px !important;
        }

        .btn-next {
            border-top-left-radius: 0px !important;
            border-bottom-left-radius: 0px !important;
        }

        .btn-next {
            border-left: none;
        }
    }

    /*.el-form-item__content {*/
    /*    margin-right: 20px*/
    /*}*/
    // 下拉选
    .el-select-dropdown__item.hover,
    .el-select-dropdown__item:hover {
        background-color: #55a8fd !important;
        color: #ffffff !important;
    }

    .el-select-dropdown__list {
        padding-top: 0px !important;
        padding-bottom: 0px !important;
        font-size: 14px !important;
        font-family: PingFang-SC-Regular !important;
        font-weight: 400;
    }

    .popper__arrow {
        display: none !important;
    }

    // 日历
    .el-picker-panel__body {
        font-family: PingFang-SC-Regular !important;
    }

    @import url('../../src/assets/less/override-element-ui.less');

</style>
